
<?php /*$this->headScript()->appendFile("http://localhost/demo2/Public/Scripts/jquery.js");*/ ?>
<?php $this->headScript()->appendFile($this->publicUrl . "/Scripts/jquery.js"); ?>

<h2><?= $this->translate("EditOfProductNumber") ?> <?= $this->product_id ?></h2>

<fieldset>
	<legend><?= $this->fieldsets->translate("EditProduct") ?></legend>	
	<?= $this->productForm ?>
</fieldset>

<script type="text/javascript">
	var changed = false;	
	$(document).ready(
		function() { 
			$("#name").change( function() { changed = true; } );
			$("#description").change( function() { changed = true; } );
			
			$("#selectLanguage").click( function() {
					if ( changed ) {
						alert("If you switch the language, all changes will be lost.");
						changed = false;
					}					
				}
			)
			$("#selectLanguage").change( function() {				
					$("#loading").html("loading").show();	
					$.get("<?= $this->url(array("controller"=>"Products","action"=>"product-Texts-Ajax")); ?>", 
						{id: $("#productId").val(), langId: $("#selectLanguage option:selected:first").val()}, 
							function(json) {								
								var data = eval('(' + json + ')');		
								$("#name").val("");
								$("#name").val(data.name);
								$("#description").val("");
								$("#description").val(data.description);
								$("#loading").text("loading").fadeOut(500);
								$("#languageId").val($("#selectLanguage option:selected:first").val());
								changed = false;								
							}
						)					
				}
			)
		});
</script>

<fieldset>
	<legend><?= $this->fieldsets->translate("EditTexts"); ?></legend>
	<select id="selectLanguage">
		<?php foreach ($this->languages as $language) { ?>
			<option value="<?= $language->getId(); ?>" 
				<?= $language->getId() == $this->textsForm->languageId->getValue() ? "selected" : ""; ?>
				>
				<?= $language->getLanguageName()."-".$language->getCultureName(); ?>
			</option>
		<?php } ?>
	</select> <span id="loading"></span>
	<?= $this->textsForm; ?>
</fieldset>